import React, { Component } from 'react'
// 写这个withFar函数,就是为了接收子组件(需要使用公共状态和逻辑的组件)
// 高阶组件这个变成技巧,一般定义函数名,就叫withXxx
export default function withFar(Son) {
  return class Far extends Component {
    state = {
      username: '',
      password: '',
      repassword: '',
    }
    handle = (name) => (e) => {
      this.setState({
        [name]: e.target.value.trim(),
      })
    }

    render() {
      return <Son {...this.state} handle={this.handle}></Son>
    }
  }
}
